/**
 * Created by suzhen on 2017/3/22.
 */


UE.registerUI('button', function (editor, uiName) {
    //注册按钮执行时的command命令，使用命令默认就会带有回退操作
    editor.registerCommand(uiName, {
        execCommand: function () {
            alert('execCommand:' + uiName);
        }
    });

    //创建一个button
    var btn = new UE.ui.Button({
        //按钮的名字
        name: uiName,
        //提示
        title: uiName,
        //需要添加的额外样式，指定icon图标，这里默认使用一个重复的icon
        cssRules: 'background-position: -500px 0;',
        //点击时执行的命令
        onclick: function () {
            //这里可以不用执行命令,做你自己的操作也可
            //editor.execCommand(uiName);
            var dialog = editor.getDialog("insertvideo");
            dialog.title = 'SWF上传';
            dialog.render();
            dialog.open();
        }
    });

    //监听当前按钮
    editor.addListener("beforeinsertvideo", _beforeInsertImage);
    //editor.addListener("afterInsertImage", _afterInsertImage);
    //editor.fireEvent("beforeInsertImage", _afterInsertImage());


    function _beforeInsertImage(t, result) {
        var fileHtml = '';
        for(var i in result){
            fileHtml += '<embed src="'+result[i].url+'" type="application/x-shockwave-flash" width="800" height="1200" quality="high" />';
            //fileHtml += '<li><a href="'+result[i].url+'" target="_blank">'+result[i].url+'</a></li>';
        }
        console.log(fileHtml);
        var ue = UE.getEditor('container');
        // ue.setContent(fileHtml);
        ue.setContent(fileHtml, true);
        return true;
    }

    //因为你是添加button,所以需要返回这个button
    return btn;
});





